import { useEffect, useState } from 'react';
import request from '@/utils/request';
export default ({ api = '/cgapi/api/oss-signature', autoFetch = true } = {}) => {
  const [OssData, setOssData] = useState<{
    accessId?: string;
    dir?: string;
    expire?: string;
    host?: string;
    policy?: string;
    signature?: string;
  }>({});
  const getOssData = async () => {
    const response = await request.get(api, { skipErrorHandler: true });
    setOssData(response);
  };
  useEffect(() => {
    if (autoFetch) {
      getOssData();
    }
  }, [autoFetch]);

  return OssData;
};
